package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo09 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输球员名称");
        String name = in.nextLine();
        System.out.println("请输入球队名称");
        String teamName = in.nextLine();
        try ( Connection conn = DBUtils.getConn()) {
            String sql = "insert into player values (null,?,?);";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,name);
            ps.setString(2,teamName);
            System.out.println(ps.toString());
//            ps.executeUpdate();
            int i = ps.executeUpdate();
            if (i>0){
                System.out.println("保存成功!");
            }else {
                System.out.println("保存失败!");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
